
/*
	设置用于保存session数据的cookie过期时间
	在http.IncomingMessage对象的session设置
	req.session.cookie.maxAge
*/

var express = require('express');
var fs = require('fs');
var app = express();

app.use(express.cookieParser());
app.use(express.session({secret: 'test'}));

app.get('/index.html', function(req, res){
	res.sendfile(__dirname + '/session_index.html');
	var hour = 3600000;
	req.session.cookie.expires = new Date(Date.now() + hour);
	req.session.cookie.maxAge = hour;

	req.session.username = 'xuxuan';
	req.session.password = '123456';
});

app.post('/index.html', function(req, res){
	console.log(req.session)
	console.log(req.session.username);
	console.log(req.session.password);
	/*
	{ cookie:
	   { path: '/',
	     _expires: Wed Oct 15 2014 11:59:14 GMT+0800 (中国标准时间),
	     originalMaxAge: 3600000,
	     httpOnly: true },
	  username: 'xuxuan',
	  password: '123456' }
	xuxuan
	123456
	*/
	res.end();
});

app.listen(1337, 'localhost');